package com.android.phpclient;


import java.util.ArrayList;
import java.util.List;

import com.utez.sistemas.sam.R;

import Clases.AlumnoDatos;
import Clases.Materias;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class Alumno extends Activity implements OnClickListener,OnItemSelectedListener{

	
	String alumnoA,carreraA,matriculaA;
	Button verCalif;
	String idCuatri;
	
	public List<String> ListaCuatri =new ArrayList<String>();
	public List<String> ListaMateria =new ArrayList<String>();
	 public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.combo_consulta);
	        
	
	        
	        Bundle bundle=getIntent().getExtras();
	        matriculaA=bundle.getString("id");
	        
	        
	        Toast.makeText(getApplicationContext(), ""+matriculaA, Toast.LENGTH_LONG).show();
        	
	        ServerAccess ss=new ServerAccess();
	        
	      
	        verCalif=(Button) findViewById(R.id.calificacion);
	        verCalif.setOnClickListener(this);
	        
	        
	        
	        Materias[] cuatri=ss.Materias_Cuatrimestre();
	       
	        
	         for(int i=0;i<cuatri.length;i++){
	        	 ListaCuatri.add(""+cuatri[i].nombre);
	          }
	         
	        
	         
	         
	         ArrayAdapter<String> adaptador = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, ListaCuatri);
	     	
	         
	         final Spinner combo = (Spinner)findViewById(R.id.materiasAlumno);
	     	adaptador.setDropDownViewResource(
	     	android.R.layout.simple_spinner_dropdown_item);
	     	combo.setAdapter(adaptador);
	     	
	     	combo.setOnItemSelectedListener(this);
	     	
	 }
	 
	 
	 
	 private class AlumnoD extends ArrayAdapter<AlumnoDatos>
		{
			
			
			//Array to have the objects
			private AlumnoDatos[] array;
			
			public AlumnoD(Context context, int textViewResourceId,AlumnoDatos[] objects) {
				super(context, textViewResourceId,objects);
				array=objects;
			}
			
			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				//Set the view for each item in the list view
				View v = convertView;
	            if (v == null) {
	                LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	                v = vi.inflate(R.layout.datos_alumno, null);
	            }
	            //Get the Textviews from the row view and set the appropriate values for them
	            TextView alumno=(TextView) v.findViewById(R.id.alumno);
	            TextView matricula=(TextView) v.findViewById(R.id.matricula);
	            TextView carrera=(TextView) v.findViewById(R.id.carrera);
	            
	            alumno.setText(array[position].alumno);
	            matricula.setText(array[position].matricula);
	            carrera.setText(array[position].nombre);
	            
	            
				return v;
			}
		}



	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
	   
		ServerAccess ss=new ServerAccess();
		 Materias[] MA=ss.Materias_Alumnos(idCuatri);
		 for(int i=0;i<MA.length;i++){
        	 ListaMateria.add(""+MA[i].nombre);
         }
		
		
		
		
		
		String filas=""+ListaMateria.size();
		Intent i=new Intent(Alumno.this,Calificaiones.class);
		
		String idA=matriculaA;
		
		Bundle bundle = new Bundle();
		bundle.putString("fila", filas);
		bundle.putString("id",idA);
		bundle.putString("idC", idCuatri);
	i.putExtras(bundle);
	startActivity(i);
	}



	@Override
	public void onItemSelected(AdapterView<?> v, View arg1, int arg2,
			long arg3) {
		// TODO Auto-generated method stub
		if(v.getId()==R.id.materiasAlumno){
			idCuatri=""+(arg2+1);
			
		}
	}



	@Override
	public void onNothingSelected(AdapterView<?> arg0) {
		// TODO Auto-generated method stub
		
	}
}
